/*
Copyright (C) 2014  Johan Degraeve

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/gpl.txt>.

*/

package helpdiabetesj2me;

import javax.microedition.lcdui.*;

/**
 *
 * @author Johan
 */
public class UserInfo implements CommandListener {
     static String str_ok[] = {"Ok"};
     static String str_info[] = {"Info"};
    
    Command done;
    Displayable curdisp;
    Form fi;
    StringItem si;
    boolean close;
    
    /** Creates a new instance of UserInfo */
    public UserInfo() {
        done = new Command(str_ok[HelpDiabetes.languageIndex],Command.EXIT,0);
        fi = new Form(str_info[HelpDiabetes.languageIndex]);
        si = new StringItem(null,null);
        fi.append(si);
        fi.addCommand(done);
        fi.setCommandListener(this);
        close = false;
    }
        
    //method to show info to the user
    //usertext : text to show
    public void  Report(String usertext)  {
        curdisp = HelpDiabetes.midlet.getDisplay().getCurrent();
        si.setText(usertext);
        HelpDiabetes.midlet.getDisplay().setCurrent(fi);
    }

    public void ReportAndSwitchDisplayable(String usertext, Displayable displayable) {
        curdisp = displayable;
        si.setText(usertext);
        HelpDiabetes.midlet.getDisplay().setCurrent(fi);
    }

    public void ReportAndClose(String usertext) {
        close = true;
        Report(usertext);
    }

    public void commandAction(Command command, Displayable displayable) {
        if (command == done) {
            if (close) {
                HelpDiabetes.midlet.exitMIDlet();
            } else {
             HelpDiabetes.midlet.getDisplay().setCurrent(curdisp);
            }
        }
    }
   
    
}
